<?php
/**
 */
// from 0 local 1 from_mblog

define("CACHE_PREFIX_PUBU","_pubu_content");

class db_mblog_pic_content extends db_base {
    
	var $table_name = "mblog_pic_content";
	
	function db_mblog_pic_content()
	{
		parent::db_base();
	}
	
	function get_index_tuijian_mblog()
	{
		$mc = mem_cache::get_instance();
		$id = intval($id);
		$key = CACHE_PREFIX_PUBU."-get_index_tuijian_mblog";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			
			$sql = "select a.*,b.user_nickname ,b.verified_type,  b.sex from mblog_pic_content a left join user_info b on a.create_uid=b.uid where b.sex=0  and b.count_mblog > 5 and a.show_type in (0,1,2) order by a.create_time desc limit 100";
			
			$content = $this->select($sql);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_HOUR);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
	
	}

	function get_mblog_pic_content_item($id)
	{
		$mc = mem_cache::get_instance();
		$id = intval($id);
		$key = CACHE_PREFIX_PUBU."-get_mblog_pic_content_item-{$id}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$where_ary = array();
			$where_ary[] = "id = $id";
			$where_ary[] = "status = 1";
			$where = join (" and ",$where_ary);
			
			$content = $this->get_alllist($this->table_name,1,1,"",$where);
			
			$content[0]["content_no_url"] =  preg_replace("/http[\S]+/","",$content[0]["content"]);
			
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	
	
	function get_mblog_pic_content_item_with_del($id)
	{
		$id = intval($id);
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_PUBU."-get_mblog_pic_content_item_with_del-{$id}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$where_ary = array();
			$where_ary[] = "id = $id";
			$where = join (" and ",$where_ary);
			
			$content = $this->get_alllist($this->table_name,1,1,"",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	function get_mblog_pubu_count_by_date($show_type="",$date="")
	{
		$show_type = mysql_escape_string($show_type);
		$date = mysql_escape_string($date);
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_PUBU."-get_mblog_pubu_count_by_date-{$show_type}-{$date}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$where_ary = array();
			if(strlen($show_type)>0)$where_ary[] = "show_type = $show_type";
			if(strlen($date)>0)$where_ary[] = "update_date = '{$date}'";
			if(strlen($status)>0)$where_ary[] = "status = $status";
			$where = join (" and ",$where_ary);
			
			$content = $this->get_listcount($this->table_name,$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	
	
	function get_mblog_pubu_list_by_ids($ids)
	{
		$mc = mem_cache::get_instance();
		
		if(is_array($ids))
		{
			$ids = array_unique($ids);
			$ids = join(",",$ids);
			
		}
		if(!$ids)
		{
			return false;
			
		}
		$key = CACHE_PREFIX_PUBU."-get_mblog_pubu_list_by_ids-$ids";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$ids = mysql_escape_string($ids);
			$where_ary = array();
			$where_ary[] = "id in ( {$ids} )";
			$where_ary[] = "status = 1";
			$where = join (" and ",$where_ary);
			
			$content = $this->get_alllist($this->table_name,$p,$pcount,"",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	

	function get_mblog_pubu_count_by_topic($topic_id="",$uid="",$tag_id="")
	{
		
		
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_PUBU."-get_mblog_pubu_count_by_topic-{$topic_id}-{$uid}-{$tag_id}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$status = mysql_escape_string($status);
			$topic_id = intval($topic_id);
			//$show_type = intval($show_type);
			$uid = intval($uid);
			$tag_id = intval($tag_id);
			
			$where_ary = array();
			if($uid)$where_ary[] = "create_uid = $uid";
			if($topic_id)$where_ary[] = "topic_id = $topic_id";
			if($tag_id)$where_ary[] = "tag_id = $tag_id";
		//	if($show_type)$where_ary[] = "show_type = $show_type";
			$where_ary[] = "status = 1";
			
			$where = join (" and ",$where_ary);
			
			$content = $this->get_listcount($this->table_name,$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	function get_mblog_pubu_list_by_topic($p=1,$pcount=10,$topic_id="",$uid="",$tag_id="",$is_check=0)
	{
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_PUBU."-get_mblog_pubu_list_by_topic-{$p}-{$pcount}-{$topic_id}-{$uid}-{$tag_id}-{$is_check}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			
			$p = intval($p);
			$pcount = intval($pcount);
			$topic_id = intval($topic_id);
			
			$status = mysql_escape_string($status);
			$show_type = intval($show_type);
			$uid = intval($uid);
			$tag_id = intval($tag_id);
			
			
			$where_ary = array();
			if($uid)$where_ary[] = "create_uid = $uid";
			if($topic_id)$where_ary[] = "topic_id = $topic_id";
			if($tag_id)$where_ary[] = "tag_id = $tag_id";
			if($is_check)$where_ary[] = "is_check = $is_check";
			$where_ary[] = "status = 1";
			$where = join (" and ",$where_ary);
			
			$content = $this->get_alllist($this->table_name,$p,$pcount,"create_time desc",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	
	function get_mblog_pubu_list_biger_by_topic_and_create_time($p=1,$pcount=10,$topic_id="",$create_time="",$tag_id="")
	{
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_PUBU."-get_mblog_pubu_list_biger_by_topic_and_id-{$p}-{$pcount}-{$topic_id}-{$create_time}-{$tag_id}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$p = intval($p);
			$pcount = intval($pcount);
			$topic_id = intval($topic_id);
			$tag_id = intval($tag_id);
			$create_time = mysql_escape_string($create_time);
			$tag_id = intval($tag_id);
			
			$where_ary = array();
			if($create_time)$where_ary[] = " create_time >= '{$create_time}'";
			if($topic_id)$where_ary[] = "topic_id = $topic_id";
			if($tag_id)$where_ary[] = "tag_id = $tag_id";
			$where_ary[] = "status = 1";
			
			$where = join (" and ",$where_ary);
			
			$content = $this->get_alllist($this->table_name,$p,$pcount,"create_time",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	
	function get_mblog_pubu_list_smaller_by_topic_and_create_time($p=1,$pcount=10,$topic_id="",$create_time="",$tag_id="")
	{
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_PUBU."-get_mblog_pubu_list_smaller_by_topic_and_create_time-{$p}-{$pcount}-{$topic_id}-{$create_time}-{$tag_id}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			
			$p = intval($p);
			$pcount = intval($pcount);
			$topic_id = intval($topic_id);
			
			$create_time = mysql_escape_string($create_time);
			$tag_id = intval($tag_id);
			
			
			$where_ary = array();
			if($create_time)$where_ary[] = " create_time <= '{$create_time}'";
			if($topic_id)$where_ary[] = "topic_id = $topic_id";
			if($tag_id)$where_ary[] = "tag_id = $tag_id";
			$where_ary[] = "status = 1";
			
			$where = join (" and ",$where_ary);
			
			$content = $this->get_alllist($this->table_name,$p,$pcount,"create_time desc",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	
	
	/*function get_mblog_pubu_list_order_by_count_tuijian($p=1,$pcount=10,$topic_id="",$status="",$show_type="",$uid="")
	{
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_PUBU."-get_mblog_pubu_list_order_by_count_tuijian-{$p}-{$pcount}-{$topic_id}-{$uid}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			
			$p = intval($p);
			$pcount = intval($pcount);
			$topic_id = intval($topic_id);
			
			$status = mysql_escape_string($status);
			$uid = intval($uid);
			$show_type = intval($show_type);
			
			$where_ary = array();
			if($uid)$where_ary[] = "create_uid = $uid";
			if($topic_id)$where_ary[] = "topic_id = $topic_id";
			if(strlen($status)>0)$where_ary[] = "status = $status";
			if($show_type)$where_ary[] = "show_type = $show_type";
			$where = join (" and ",$where_ary);
			
			$content = $this->get_alllist($this->table_name,$p,$pcount," update_date desc  ",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}*/
	
	
	function update_mblog_info_by_id($id,$status="",$count_love="",$count_reply="")
	{
		$id = intval($id);
		$where = "id = $id";
		$ary = array();

		if(strlen($status)>0)$ary["status"] = $status;
		$count_tuijian=0;
		if(strlen($count_love)>0)
		{
			$ary["count_love"] = "count_love+{$count_love}";
			$count_tuijian ++;
		}
		if(strlen($count_reply)>0)
		{
			$ary["count_reply"] = "count_reply+{$count_reply}";
			$count_tuijian ++;
		}
		
		
		if($count_tuijian)
		{
			$ary["count_tuijian"] = "count_tuijian+{$count_tuijian}";
			
		}
		
		$ret = $this->update($this->table_name, $ary,$where);
		
		return $ret;
	}
	
	function insert_mblog_pic_content_by_cron_id($id)
	{
		// 插入数据
		$ary = array();
		$from = "topic_mblog";
		$sql ="insert ignore into {$this->table_name} (`from`,mid,content,md5_content,topic_id,topic,pic,pic_width_pubu,pic_height_pubu,split_word,source,location,coordinates,create_uid,create_nickname,create_time,create_ip,status,count_love) select '1',id,content,md5(content),topic_id,topic,pic,pic_width_pubu,pic_height_pubu,split_word,source,location,coordinates,create_uid,create_nickname,create_time,create_ip,status ,count_love from mblog_cron_content where id =$id";
		
		$ret = $this->query($sql);
	
		return $ret;
	}
	

	function insert_mblog_pic_content($content,$topic_id,$topic,$pic,$pic_width_pubu,$pic_height_pubu,$source,$show_type,$from,$uid,$nickname)
	{
		if(!$topic) $topic= "";
		$ary["content"] = $content;
		
		
		$mid = php_patch::php_crc32("{$uid}".time());
		$now = time();
		$now = $now - ($now %3);
		$md5_key = $uid.$now;//内容保持唯一
		$md5_key =  md5($md5_key);
		
		$ary["md5_key"] = $md5_key;
		$ary["topic_id"] = $topic_id;
		$ary["topic"] = $topic;
		
		$ary["pic"] = $pic;
		$ary["pic_width_pubu"] = $pic_width_pubu;
		$ary["pic_height_pubu"] = $pic_height_pubu;
		$ary["source"] = $source;
		$ary["show_type"] = $show_type;
		$ary["from"] = $from;
		$ary["mid"] = $mid;
		
		
		
		$ary["status"] = 1;
		$ary["create_uid"] = $uid;
		$ary["create_nickname"] = $nickname;
		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["update_date"] = time();
		$ret = $this->insert($this->table_name, $ary );
		
		
		
		
		
		return $this->get_lastinsertid();
		
	}

	
###########################

	
		/**
	 * 用户注册
	 * @param $user_name
	 * @param $password
	 */
	function admin_insert_mblog_pic_content_by_cron_id($id)
	{
		// 插入数据
		$ary = array();
		$from = "topic_mblog";
		
		
		
		$sql ="insert ignore into {$this->table_name} (show_type,`from`,mid,content,md5_content,topic_id,topic,pic,pic_width_pubu,pic_height_pubu,split_word,source,location,coordinates,create_uid,create_nickname,create_time,create_ip,status,count_love) select show_type,'1',id,content,md5(content),topic_id,topic,pic,pic_width_pubu,pic_height_pubu,split_word,source,location,coordinates,create_uid,create_nickname,create_time,create_ip,status,count_love from mblog_cron_content where id =$id";
		
		$ret = $this->query($sql);
	
		return $ret;
	}
	
	
	/**
	 * cron 获取food_tag
	 */
	function admin_get_count_by_search($is_check="",$min_height="",$max_height="",$uid="",$topic_id="")
	{
		$where= array();
		if(strlen($is_check) > 0)
		{
			$where[] = "is_check = {$is_check}";
		}
		
		if($min_height) 
		{
			$where[] = "pic_height_pubu > '{$min_height}'";
		}
		if($max_height)
		{
			$where[] = "pic_height_pubu < '{$max_height}'";
		}
	if($uid)
		{
			$where[] = "create_uid = '{$uid}'";
		}
		if($topic_id)
		{
			$where[] = "topic_id = '{$topic_id}'";
		}
		$where[] = "status = 1";
		
		$where= join(" and ",$where);
		
		$data = $this->get_listcount($this->table_name, $where);
		
		return $data;
	}
	
	
	/*
	 * cron获取topic_lisy
	 */
	function admin_get_list_by_search($is_check="",$p=1,$pcount=10,$min_height="",$max_height="",$uid="",$topic_id="")
	{
		$where= array();
		if(strlen($is_check) > 0)
		{
			$where[] = "is_check = {$is_check}";
		}
		if($min_height) 
		{
			$where[] = "pic_height_pubu > '{$min_height}'";
		}
		if($max_height)
		{
			$where[] = "pic_height_pubu < '{$max_height}'";
		}
		if($uid)
		{
			$where[] = "create_uid = '{$uid}'";
		}
	if($topic_id)
		{
			$where[] = "topic_id = '{$topic_id}'";
		}
		$where[] = "status = 1";
		$where= join(" and ",$where);
		
		$p = intval($p);
		$pcount = intval($pcount);
		
		
		$data = $this->get_alllist($this->table_name,$p,$pcount,"create_time desc",$where);
		
		return $data;
	}
	
		
	function admin_update_mblog_info_by_id($id,$status="",$is_check="")
	{
		$where = "id = $id";
		$ary = array();

		if(strlen($status)>0)$ary["status"] = $status;
		if(strlen($is_check)>0)$ary["is_check"] = $is_check;
		$ret = $this->update($this->table_name, $ary,$where);
		
		return $ret;
	}
	
	
	function admin_insert_mblog_pic_content($content,$topic_id,$topic,$pic,$pic_width_pubu,$pic_height_pubu,$source,$show_type,$from,
	$uid,$nickname,$update_date,$mid,$create_time,$count_love,$head_url,$tag_id,$tag_name)
	{
		$content = preg_replace("/\<.*?\>/","",$content);
		if(!$mid)
		{
			return false;
		}
		//内容先转码
		$content = html_entity_decode($content,ENT_QUOTES);
		//删除@信息
		$check_content= preg_replace("/@([\x{4e00}-\x{9fa5}0-9A-Za-z_\-]+)/u","",$content);
		
		
		//删除除了汉字和字母数字外的其他字符
		$check_content = preg_replace("/#.*?#/","",$check_content);
		$check_content= preg_replace("/[^\x{4e00}-\x{9fa5}]+/u","",$check_content);
		if(strlen($check_content) > 30)//如果是15个中文字符长度以上，就需要判断内容做key
		{
			$md5_key = $check_content;//内容保持唯一
			$md5_key =  md5($md5_key);
			
			
		}
		else
		{
			$find_content = $check_content;
			$md5_key = $mid;
			$md5_key =  md5($md5_key);
		}
		
		//抓取图片
		
		$res = get_image::get_down_image_size($pic);
		$md5_file = $res["md5_file"];
		$srcW = $res["width"]; 
		$srcH = $res["height"]; 
		
		$pic_width_pubu = PUBU_WIDTH;
		$pic_height_pubu = intval($srcH/($srcW/$pic_width_pubu));
		
		$ary["md5_file"] = $md5_file;
		$ary["tag_id"] = $tag_id;
		$ary["tag_name"] = $tag_name;
		$ary["count_love"] = $count_love;
		$ary["content"] = $content;
		$ary["content_index"] = $find_content;
		$ary["md5_key"] = $md5_key;
		$ary["topic_id"] = $topic_id;
		$ary["topic"] = $topic;
		$ary["pic"] = $pic;
		$ary["pic_width_pubu"] = $pic_width_pubu;
		$ary["pic_height_pubu"] = $pic_height_pubu;
		$ary["source"] = $source;
		$ary["show_type"] = $show_type;
		$ary["from"] = $from;
		$ary["mid"] = $mid;
		$ary["head_url"] = $head_url;
		
		
		
		$ary["status"] = 1;
		$ary["create_uid"] = $uid;
		$ary["create_nickname"] = $nickname;
		$ary["create_time"] = $create_time;
		$ary["create_ip"] = 0;
		
		$update_date = strtotime($create_time);
		if($count_love)$update_date = log($count_love)*86400 + $update_date;
		$ary["update_date"] = $update_date;
		
		
		$ret = $this->insert($this->table_name, $ary );
		if($ret)
		{
			return $this->get_lastinsertid();
		}
		else
		{
			return false;
		}
		
	}
	
	
	
	
function cron_get_data_list_width_wrong($p,$pcount)
	{
		
		$where = "pic_height_pubu = 0 and pic!='' and create_ip != -1";
		$data = $this->get_alllist($this->table_name,$p,$pcount,"",$where);
		return $data;
	}
	
	
#######################	
	function cron_get_data_count_width_wrong()
	{
		
		$where = "pic_height_pubu = 0 and pic!='' and create_ip != -1";
		$data = $this->get_listcount($this->table_name,$where);
		return $data;
	}
	
	function cron_update_mblog_info_by_id($id,$pic_width_pubu="",$pic_height_pubu="",$status="")
	{
		$where = "id = $id";
		$ary = array();

		if(strlen($pic_width_pubu)>0)$ary["pic_width_pubu"] = $pic_width_pubu;
		if(strlen($pic_height_pubu)>0)$ary["pic_height_pubu"] = $pic_height_pubu;
		if(strlen($status)>0)$ary["status"] = $status;
		$ret = $this->update($this->table_name, $ary,$where);
		
		return $ret;
	}
	
  	function get_user_order_by_count_tuijian_nocache($show_type,$p,$pcount)
	{
		$db_mblog_cron_topic_tag = new db_mblog_cron_topic_tag();
		$topic_list = $db_mblog_cron_topic_tag->get_mblog_cron_topic_tag_list_order_by_like($show_type,1,10);
		
		
		$content = array();
		foreach($topic_list as $value)
		{
			$topic_id = $value["id"];
			$sql ="select * from mblog_pic_content where topic_id = $topic_id order by  update_date desc , count_tuijian desc limit 1";
			
			$res = $db_mblog_cron_topic_tag->select($sql);
			
			$res = $res[0];
			$content[] = $res;
		}
		
		return $content ;
	}
	
	
	
	function cron_insert_mblog_pic_content($content,$topic_id,$topic,$pic,$pic_width_pubu,$pic_height_pubu,$source,$show_type,$from,
	$uid,$nickname,$update_date,$mid,$create_time,$count_love,$head_url,$tag_id,$tag_name)
	{
		$content = preg_replace("/\<.*?\>/","",$content);
		if(!$mid)
		{
			return false;
		}
		//内容先转码
		$content = html_entity_decode($content,ENT_QUOTES);
		//删除@信息
		$check_content= preg_replace("/@([\x{4e00}-\x{9fa5}0-9A-Za-z_\-]+)/u","",$content);
		echo "check_content : $check_content \n";
		
		if($topic)
		{
			if(stripos($check_content,$topic)=== false)//删除@信息后检查话题是否在内容里，如果不在返回错误
			{
				$check_content_at = preg_match_all("/@([\x{4e00}-\x{9fa5}0-9A-Za-z_\-]+)/u",$content,$match);
				
				if($match[1])
				{
					
					foreach($match[1] as $value) //如果在外部内容找不到这个话题，并且在用户名里找到这个话题，返回false
					{
						if(stripos($value,$topic) !== false)
						{
							echo "false \n";
							return false;
						}
					
					}
				
				}
			}
				
		}
		
		//删除除了汉字和字母数字外的其他字符
		$check_content = preg_replace("/#.*?#/","",$check_content);
		$check_content= preg_replace("/[^\x{4e00}-\x{9fa5}]+/u","",$check_content);
		if(strlen($check_content) > 30)//如果是15个中文字符长度以上，就需要判断内容做key
		{
			
		
			//如果数据库里已经有这样的数据，不入库
			$find_content = string_utf8::substr_utf8_cn_v2($check_content,60);
			$get_res_count = $this->cron_get_mblog_count_search_content($find_content);
			if($get_res_count > 0)
			{
				return false;
			}
			
			
			$md5_key = $check_content;//内容保持唯一
			$md5_key =  md5($md5_key);
			
			
		}
		else
		{
			$find_content = $check_content;
			$md5_key = $mid;
			$md5_key =  md5($md5_key);
		}
		
		//抓取图片
		echo "image:{$pic}\n";
		$res = get_image::get_down_image_size($pic);
		$md5_file = $res["md5_file"];
		$srcW = $res["width"]; 
		$srcH = $res["height"]; 
		if($srcW < 220) //实际大小已经小于220的就不要
		{
			echo "width < 220 : {$srcW} \n";
			return false;
		}
		
		$pic_width_pubu = PUBU_WIDTH;
		$pic_height_pubu = intval($srcH/($srcW/$pic_width_pubu));
		
		if($pic_height_pubu < 80)
		{
			echo "height < 80 : {$pic_height_pubu} \n";
			return false;
		}
		$ary["md5_file"] = $md5_file;
		$ary["tag_id"] = $tag_id;
		$ary["tag_name"] = $tag_name;
		$ary["count_love"] = $count_love;
		$ary["content"] = $content;
		$ary["content_index"] = $find_content;
		$ary["md5_key"] = $md5_key;
		$ary["topic_id"] = $topic_id;
		$ary["topic"] = $topic;
		$ary["pic"] = $pic;
		$ary["pic_width_pubu"] = $pic_width_pubu;
		$ary["pic_height_pubu"] = $pic_height_pubu;
		$ary["source"] = $source;
		$ary["show_type"] = $show_type;
		$ary["from"] = $from;
		$ary["mid"] = $mid;
		$ary["head_url"] = $head_url;
		
		
		
		$ary["status"] = 1;
		$ary["create_uid"] = $uid;
		$ary["create_nickname"] = $nickname;
		$ary["create_time"] = $create_time;
		$ary["create_ip"] = 0;
		
		$update_date = strtotime($create_time);
		if($count_love)$update_date = log($count_love)*86400 + $update_date;
		$ary["update_date"] = $update_date;
		
		
		$ret = $this->insert($this->table_name, $ary );
		if($ret)
		{
			return $this->get_lastinsertid();
		}
		else
		{
			echo "insert mysql false \n;";
			
			return false;
		}
		
	}
	
	
	
	function cron_biaoqian_insert_mblog_pic_content($content,$topic_id,$topic,$pic,$pic_width_pubu,$pic_height_pubu,$source,$show_type,$from,
	$uid,$nickname,$update_date,$mid,$create_time,$count_love)
	{
		
		if(!$mid)
		{
			return false;
		}
		
		$content = preg_replace("/\<.*?\>/","",$content);
		
		$md5_key = $mid;
		$md5_key =  md5($md5_key);
		
		$ary["count_love"] = $count_love;
		$ary["content"] = $content;
		$ary["md5_key"] = $md5_key;
		$ary["topic_id"] = $topic_id;
		$ary["topic"] = $topic;
		$ary["pic"] = $pic;
		$ary["pic_width_pubu"] = $pic_width_pubu;
		$ary["pic_height_pubu"] = $pic_height_pubu;
		$ary["source"] = $source;
		$ary["show_type"] = $show_type;
		$ary["from"] = $from;
		$ary["mid"] = $mid;
		
		
		
		$ary["status"] = 1;
		$ary["create_uid"] = $uid;
		$ary["create_nickname"] = $nickname;
		$ary["create_time"] = $create_time;
		$ary["create_ip"] = 0;
		
		$update_date = strtotime($create_time);
		if($count_love)$update_date = log($count_love)*86400 + $update_date;
		$ary["update_date"] = $update_date;
		
		
		$ret = $this->insert($this->table_name, $ary );
		
		return $this->get_lastinsertid();
		
	}
	
	
	//抓取用户最近的微博
	function cron_get_mblog_count_search_content($content)
	{
		$where = "content_index  like '{$content}%' ";
		
		$count = $this->get_listcount($this->table_name,$where)	;
		
		return $count;
	}
	
	
	//抓取用户最近的微博
	function cron_get_mblog_list_order_by_create_time($uid,$p=1,$pcount=10)
	{
		$where = "create_uid = {$uid} and status = 1";
		$list = $this->get_alllist($this->table_name,$p,$pcount,"create_time",$where)	;
		return $list;
	}
	
	
	
	function cron_get_min_time_by_topic($topic_id)
	{
		$sql ="select min(create_time) as create_time from mblog_pic_content where topic_id =  $topic_id and create_ip = 0";
		
		$res = $this->select($sql);
	
		return $res;
	}
	
	
	function cron_get_count_by_mid($mid)
	{
		$where = "mid = '{$mid}'";
		
		$count = $this->get_listcount($this->table_name,$where);
		
		return $count;
		
	}
	function cron_get_list_for_reply_from_sina($p,$pcount,$id)
	{
		$where = "id > $id and status = 1 ";
		$data = $this->get_alllist($this->table_name,$p,$pcount,"id",$where);
	
		return $data;
	}
	
	
	
	function cron_update_mblog_count_reply($id)
	{
		$db_mblog_reply = new db_mblog_reply();
		
		$count = $db_mblog_reply->cron_get_count_by_mid($id);
		
		$sql = "update {$this->table_name} set count_reply = $count where id = $id ";
		$this->query($sql);
		
		
	}
}



